<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>猜数字</title>
</head>
<body>
    <button onclick="alert('警告信息')">测试警告框</button>
    <button onclick="confirm('您确认要关闭吗?')">测试确认框</button>
    <button onclick="prompt('请输入你的设备')">测试输入框</button>
    <hr>
    <h3>已生成一个1~100之间的随机数</h3>
    <input type="text">
    <button onclick="yanzheng()">点我验证</button>
    <button onclick="xiaochao()">打个小抄</button>
    <br>
    <span id="s1"></span>
    <span id="s2"></span>

    <script>
        let r = parseInt(Math.random()*100)+1;
        console.log(r)
        let span2 = document.getElementById("s1");
        console.log(span2)
        let count = 0;
        function xiaochao() {
            let span1 = document.getElementById("s2");
            span1.innerHTML=String(r);
        }
        function yanzheng() {

            let value = parseInt(document.querySelector("input").value);
            console.log(value)

            if (value !== r){
                count++;
                console.log(count)
            }
            if (r === value){
                span2.innerHTML ="恭喜你,用了"+(count+1)+"次猜对了";
            }
        }
    </script>
</body>
</html>